package com.wzdigit.wms.wms.controller.TransferWareHouse;

import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.basic.util.HttpSessionUtil;
import com.wzdigit.wms.basic.client.request.transfer.SplitAndMergerCommitReq;
import com.wzdigit.wms.basic.client.request.transfer.SplitAndMergerScanReq;
import com.wzdigit.wms.basic.client.response.Result;
import com.wzdigit.wms.basic.client.response.transfer.SnLocationResponse;
import com.wzdigit.wms.wms.constant.WmsWareConstant;
import com.wzdigit.wms.wms.service.transfer.SplitAndMergerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName TransferLocationController
 * @Description 在库模块-拆并板
 * @Author LHR-PC
 * @Date 2021/3/22 10:00
 * @Version
 **/

@RestController
@Api(tags = "在库模块-拆并板")
@RequestMapping(value = WmsWareConstant.API_VERSION)
public class SplitAndMergerController {

    private static final String REQUEST_MODEL = "/splitAndMerger";

    @Autowired
    private SplitAndMergerService splitAndMergerService;

    @ApiOperation(value = "扫描条码", notes = "扫描条码")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @GetMapping(value = REQUEST_MODEL + "/list")
    public SnLocationResponse list(SplitAndMergerScanReq splitAndMergerScanReq,
                                   HttpServletRequest servletRequest,
                                   HttpServletResponse servletResponse) {
        try {
            return splitAndMergerService.scanSn(splitAndMergerScanReq);
        } catch (Exception ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "提交", notes = "提交")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @PostMapping(value = REQUEST_MODEL + "/commit")
    public Result<?> commit(@RequestBody SplitAndMergerCommitReq splitAndMergerCommitReq,
                            HttpServletRequest servletRequest,
                            HttpServletResponse servletResponse) throws Exception {
        try {
            return splitAndMergerService.commit(splitAndMergerCommitReq, HttpSessionUtil.getLoginName(servletRequest));
        } catch (Exception ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

}
